package com.hoshiicloud.goods.controller;


import com.hoshiicloud.common.query.OmnipotentParam;
import com.hoshiicloud.common.query.OmnipotentWrapper;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.goods.entity.spu.BaseGoodsGallery;
import com.hoshiicloud.goods.service.BaseGoodsGalleryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品baseSpu相册关联 控制器
 * </p>
 *
 * @author zhangshuhu
 * @since 2019-06-04
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/goods/base-goods-gallery")
@Api(value = "商品baseSpu相册关联表", tags = {"商品baseSpu相册关联表"})
public class BaseGoodsGalleryController {
    @Autowired
    private BaseGoodsGalleryService baseGoodsGalleryService;


    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量新增baseSpu相册信息")
    public Response saveGalleryBatch(@RequestBody List<BaseGoodsGallery> galleries) {
        return Response.data(baseGoodsGalleryService.saveBaseGoodsGalleryBatch(galleries));
    }

    @DeleteMapping("/removeBatch")
    @ApiOperation(value = "批量删除: 物理删除")
    public Response removeBatch(@RequestBody List<OmnipotentWrapper> param) {
        return Response.data(baseGoodsGalleryService.removeBatch(param));
    }

    @PostMapping("/updateBatch")
    @ApiOperation(value = "批量更新baseSpu相册信息")
    public Response updateBatch(@RequestBody OmnipotentParam<BaseGoodsGallery> param) {
        return Response.data(baseGoodsGalleryService.updateBatch(param));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除基础SKU商品图片资源")
    @ApiParam(name = "id", value = "主键ID", required = true)
    public Response delete(@PathVariable("id") Long id) {
        return Response.data(baseGoodsGalleryService.deleteById(id));
    }

    @ApiOperation(value = "通过baseSpuId查询相册信息")
    @GetMapping("/listBySpuIds/{baseSpuId}")
    public Response listBySpuId(@PathVariable("baseSpuId") Long baseSpuId) {
        return Response.data(baseGoodsGalleryService.listBySpuId(baseSpuId));
    }
}
